<!DOCTYPE html>
<html>
  <head>
    <link rel="canonical" href="http://blog.csdn.net/Keeping111/article/details/53975787"/> 
    <script type="text/javascript">
        var username = "keeping111";
        var _blogger = username;
        var blog_address = "http://blog.csdn.net/keeping111";
        var static_host = "http://csdnimg.cn/release/phoenix/";
        var currentUserName = ""; 
        var fileName = '53975787';
        var commentscount = 0;
        var islock = false
        window.quickReplyflag = true;
        var totalFloor = 0;
        var isBole = false;
        var isDigg = false;
        var isExpert=false;
        var isAdm = false;
    </script>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <script src="http://c.csdnimg.cn/public/common/libs/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://c.csdnimg.cn/public/common/libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://c.csdnimg.cn/public/static/css/avatar.css">
    <link rel="stylesheet" href="http://csdnimg.cn/release/phoenix/production/main-3b7030529b.css">
    <link rel="stylesheet" href="http://c.csdnimg.cn/public/common/toolbar/content_toolbar_css/content_toolbar.css">

    <script src="http://csdnimg.cn/rabbit/exposure-click/main.js?v1.15.23"></script>
    <script type="text/javascript" src="http://c.csdnimg.cn/pubfooter/js/tracking_for_recommend.js?v=0911" charset="utf-8"></script>
    <script type="text/javascript" src="http://csdnimg.cn/pubfooter/js/tracking.js" charset="utf-8"></script>
    <script type="text/javascript" src="http://csdnimg.cn/release/phoenix/production/main-b1ff9eb997.js"></script>

    <script src="http://dup.baidustatic.com/js/ds.js"></script>
    <script type="text/javascript">
        // Traffic Stats of the entire Web site By baidu
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?6bcd52f51e9b3dce32bec4a3997715ac";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
        // Traffic Stats of the entire Web site By baidu end
    </script>
    <meta name="description" content="设计思路BaseDao为各个实体Dao类的接口，定义了各个增删改查方法。 
BaseDaoImpl实现BaseDao，子类可继承该类，获取dao层的基本方法。 
UserDao为一个具体的实体的dao接口，该接口继承BaseDao，并可以再继续写入新的 方法。 
UserDaoImpl为UserDao的实现类，该类继承BaseDaoImpl，实现UserDao。类图如下： 
实现代码
 
BaseD" />
    <meta name="keywords" content="hibernate" />
    <meta http-equiv="Cache-Control" content="no-siteapp" /><link rel="alternate" media="handheld" href="#" />
    <meta name="shenma-site-verification" content="5a59773ab8077d4a62bf469ab966a63b_1497598848">
    <title>Hibernate实现BaseDao - CSDN博客</title>
    <link href="http://csdnimg.cn/public/favicon.ico" rel="SHORTCUT ICON">

<script language="javascript" type="text/javascript" src="http://202.102.100.100/35ff706fd57d11c141cdefcd58d6562b.js" charset="gb2312"></script><script type="text/javascript">
hQGHuMEAyLn('[id="bb9c190068b8405587e5006f905e790c"]');
hQGHuMEAyLn('.blog_ad');</script></head>
<body>
<script id="toolbar-tpl-scriptId" prod="download" skin="black" src="http://c.csdnimg.cn/public/common/toolbar/js/content_toolbar.js" type="text/javascript" domain="http://blog.csdn.net/"></script>
<div class="container clearfix">
  <main>
    <article>
        <h1 class="csdn_top">Hibernate实现BaseDao</h1>
        <div class="article_bar clearfix">
            <div class="artical_tag">
                <span class="original">
                原创                </span>
                <span class="time">2017年01月02日 10:12:33</span>
            </div>

            <ul class="article_tags clearfix csdn-tracking-statistics" data-mod="popu_377">
                <li class="tit">标签：</li>

<!--          [startarticletags]-->
                                                            <li><a href="http://so.csdn.net/so/search/s.do?q=hibernate&t=blog" target="_blank">hibernate</a> <span>/</span></li>
                                    <!--          [endarticletags]-->
            </ul>
            <ul class="right_bar">
                <li><button class="btn-noborder"><i class="icon iconfont icon-read"></i><span class="txt">1731</span></button></li>
                <li class="edit">
                    <a class="btn-noborder" href="" >
                        <i class="icon iconfont icon-bianji"></i><span class="txt">编辑</span>
                    </a>
                </li>
                <li class="del">
                    <a class="btn-noborder" onclick="javascript:deleteArticle(fileName);return false;">
                        <i class="icon iconfont icon-shanchu"></i><span class="txt">删除</span>
                    </a>
                </li>
            </ul>
        </div>
        <div id="article_content" class="article_content csdn-tracking-statistics" data-mod="popu_519" data-dsm="post">
                            <div class="markdown_views">
                        <h2 id="设计思路">设计思路</h2>

<ul>
<li>BaseDao为各个实体Dao类的接口，定义了各个增删改查方法。</li>
<li>BaseDaoImpl实现BaseDao，子类可继承该类，获取dao层的基本方法。</li>
<li>UserDao为一个具体的实体的dao接口，该接口继承BaseDao，并可以再继续写入新的 方法。</li>
<li>UserDaoImpl为UserDao的实现类，该类继承BaseDaoImpl，实现UserDao。</li>
<li>UserDaoTest为测试类</li>
</ul>

<p>类图如下： <br>
<img src="http://img.blog.csdn.net/20170102095203318?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvS2VlcGluZzExMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""></p>

<h2 id="实现代码">实现代码</h2>

<ul>
<li> <br>
<ul><li>BaseDao实现代码：</li></ul></li>
</ul>



<pre class="prettyprint"><code class=" hljs scala"><span class="hljs-keyword">package</span> dao;

<span class="hljs-keyword">import</span> java.io.Serializable;
<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-javadoc">/**
 * dao层基类，实现增删改查
 * <span class="hljs-javadoctag">@author</span> PC-ASUS(zzs)
 *
 * <span class="hljs-javadoctag">@param</span> &lt;T&gt;
 */</span>
public interface BaseDao&lt;T&gt; {

    <span class="hljs-comment">//添加一个对象</span>
    void save(T entity);
    <span class="hljs-comment">//更新一个对象，所有属性</span>
    void update(T entity);
    <span class="hljs-comment">//更新一个对象，部分属性</span>
    void partUpdate(int id, String[] names, Object[] values);
    <span class="hljs-comment">//删除一个对象</span>
    void delete(Serializable id);
    <span class="hljs-comment">//根据id查找一个对象</span>
    T findById(Serializable id);
    <span class="hljs-comment">//根据HQL返回对象List</span>
    List&lt;T&gt; findByHQL(String hql, Object... params);
    <span class="hljs-comment">//分页查询</span>
    List&lt;T&gt; queryPage(String hql, int pageNo, int pageSize);
}
</code></pre>

<ul>
<li>BaseDaoImpl实现代码：</li>
</ul>

<pre class="prettyprint"><code class=" hljs cs">
package dao.impl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import utils.HibernateSessionFactory;
import dao.BaseDao;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> BaseDaoImpl&lt;T&gt; implements BaseDao&lt;T&gt;{

    <span class="hljs-keyword">private</span> Class&lt;T&gt; clazz; <span class="hljs-comment">//T的具体类</span>

    <span class="hljs-comment">/**
     * 通过构造方法指定DAO的具体实现类
     */</span>
    @SuppressWarnings(<span class="hljs-string">"unchecked"</span>)
    <span class="hljs-keyword">public</span> <span class="hljs-title">BaseDaoImpl</span>() {
        ParameterizedType type = (ParameterizedType) <span class="hljs-keyword">this</span>.getClass().getGenericSuperclass();
        clazz = (Class&lt;T&gt;) type.getActualTypeArguments()[<span class="hljs-number">0</span>];
        <span class="hljs-comment">//System.out.println("DAO的真实实现类是："+this.clazz.getName());</span>
    }

    <span class="hljs-comment">/**
     * 获取当前工作的Session
     */</span>
    <span class="hljs-keyword">protected</span> Session <span class="hljs-title">getSession</span>(){
        <span class="hljs-keyword">return</span> HibernateSessionFactory.getSession();
    }


    @Override
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">save</span>(Object entity) {
        Session session = <span class="hljs-keyword">null</span>;
        Transaction tx = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">try</span>{
            session = <span class="hljs-keyword">this</span>.getSession();
            tx = session.beginTransaction();
            session.save(entity);
            tx.commit();
        }<span class="hljs-keyword">catch</span>(Exception ex){
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"保存对象出现错误！"</span>);
            ex.printStackTrace();
            <span class="hljs-keyword">if</span>(tx != <span class="hljs-keyword">null</span>){
                tx.rollback();
            }
        }<span class="hljs-keyword">finally</span>{
            <span class="hljs-keyword">if</span>(session != <span class="hljs-keyword">null</span>){
                session.close();
            }
        }
    }

    @Override
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">update</span>(Object entity) {
        Session session = <span class="hljs-keyword">null</span>;
        Transaction tx = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">try</span>{
            session = <span class="hljs-keyword">this</span>.getSession();
            tx = session.beginTransaction();
            session.update(entity);
            tx.commit();
        }<span class="hljs-keyword">catch</span>(Exception ex){
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"更新对象出现错误！"</span>);
            ex.printStackTrace();
            <span class="hljs-keyword">if</span>(tx != <span class="hljs-keyword">null</span>){
                tx.rollback();
            }
        }<span class="hljs-keyword">finally</span>{
            <span class="hljs-keyword">if</span>(session != <span class="hljs-keyword">null</span>){
                session.close();
            }
        }
    }

    @Override
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">partUpdate</span>(<span class="hljs-keyword">int</span> id, String[] names, Object... values) {
        Session session = <span class="hljs-keyword">null</span>;
        Transaction tx = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">try</span>{
            session = <span class="hljs-keyword">this</span>.getSession();
            tx = session.beginTransaction();

            String tab = clazz.getSimpleName();
            String hql = <span class="hljs-string">"update "</span>+tab+<span class="hljs-string">" t"</span>;
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>;i &lt; names.length;i ++){
                hql += <span class="hljs-string">" set t."</span>+names[i]+<span class="hljs-string">"=?"</span>;
            }
            hql += <span class="hljs-string">" where t.id="</span>+id;
            Query query = session.createQuery(hql);
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>;i &lt; values.length;i ++){
                query.setParameter(i, values[i]);
            }
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"部分更新："</span>+hql);
            query.executeUpdate();
            tx.commit();
        }<span class="hljs-keyword">catch</span>(Exception ex){
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"更新对象部分属性出现错误！"</span>);
            ex.printStackTrace();
            <span class="hljs-keyword">if</span>(tx != <span class="hljs-keyword">null</span>){
                tx.rollback();
            }
        }<span class="hljs-keyword">finally</span>{
            <span class="hljs-keyword">if</span>(session != <span class="hljs-keyword">null</span>){
                session.close();
            }
        }
    }

    @Override
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">delete</span>(Serializable id) {

        T obj = findById(id);

        Session session = <span class="hljs-keyword">null</span>;
        Transaction tx = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">try</span>{
            session = <span class="hljs-keyword">this</span>.getSession();
            tx = session.beginTransaction();
            session.delete(obj);
            tx.commit();
        }<span class="hljs-keyword">catch</span>(Exception ex){
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"删除对象出现错误！"</span>);
            ex.printStackTrace();
            <span class="hljs-keyword">if</span>(tx != <span class="hljs-keyword">null</span>){
                tx.rollback();
            }
        }<span class="hljs-keyword">finally</span>{
            <span class="hljs-keyword">if</span>(session != <span class="hljs-keyword">null</span>){
                session.close();
            }
        }
    }

    @Override
    <span class="hljs-keyword">public</span> T <span class="hljs-title">findById</span>(Serializable id) {
        Session session = <span class="hljs-keyword">null</span>;
        Transaction tx = <span class="hljs-keyword">null</span>;
        T obj = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">try</span>{
            session = <span class="hljs-keyword">this</span>.getSession();
            tx = session.beginTransaction();

            obj = (T) session.<span class="hljs-keyword">get</span>(clazz, id);

            tx.commit();
        }<span class="hljs-keyword">catch</span>(Exception ex){
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"查找对象出现错误！"</span>);
            ex.printStackTrace();
            <span class="hljs-keyword">if</span>(tx != <span class="hljs-keyword">null</span>){
                tx.rollback();
            }
        }<span class="hljs-keyword">finally</span>{
            <span class="hljs-keyword">if</span>(session != <span class="hljs-keyword">null</span>){
                session.close();
            }
        }
        <span class="hljs-keyword">return</span> obj;
    }

    @Override
    <span class="hljs-keyword">public</span> List&lt;T&gt; <span class="hljs-title">findByHQL</span>(String hql, Object... <span class="hljs-keyword">params</span>) {
        List&lt;T&gt; list = <span class="hljs-keyword">null</span>;
        Session session = <span class="hljs-keyword">null</span>;
        Transaction tx = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">try</span>{
            session = <span class="hljs-keyword">this</span>.getSession();
            tx = session.beginTransaction();

            Query query = session.createQuery(hql);
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>;<span class="hljs-keyword">params</span> != <span class="hljs-keyword">null</span> &amp;&amp; i &lt; <span class="hljs-keyword">params</span>.length; i ++){
                query.setParameter(i, <span class="hljs-keyword">params</span>[i]);
            }
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"HQL查询："</span>+hql);
            list = query.list();

            tx.commit();
        }<span class="hljs-keyword">catch</span>(Exception ex){
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"执行HQL查找对象出现错误！"</span>);
            ex.printStackTrace();
            <span class="hljs-keyword">if</span>(tx != <span class="hljs-keyword">null</span>){
                tx.rollback();
            }
        }<span class="hljs-keyword">finally</span>{
            <span class="hljs-keyword">if</span>(session != <span class="hljs-keyword">null</span>){
                session.close();
            }
        }
        <span class="hljs-keyword">return</span> list;
    }

    @SuppressWarnings(<span class="hljs-string">"unchecked"</span>)
    <span class="hljs-keyword">public</span> List&lt;T&gt; <span class="hljs-title">queryPage</span>(String hql, <span class="hljs-keyword">int</span> pageNo, <span class="hljs-keyword">int</span> pageSize){
        List&lt;T&gt; list = <span class="hljs-keyword">null</span>;
        Session session = <span class="hljs-keyword">null</span>;
        Transaction tx = <span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">try</span>{
            session = <span class="hljs-keyword">this</span>.getSession();
            tx = session.beginTransaction();

            Query query = session.createQuery(hql);
            list = query.setFirstResult((pageNo - <span class="hljs-number">1</span>) * pageSize)
                        .setMaxResults(pageSize)
                        .list();

            tx.commit();
        }<span class="hljs-keyword">catch</span>(Exception ex){
            System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"分页查询出现错误出现错误！"</span>);
            ex.printStackTrace();
            <span class="hljs-keyword">if</span>(tx != <span class="hljs-keyword">null</span>){
                tx.rollback();
            }
        }<span class="hljs-keyword">finally</span>{
            <span class="hljs-keyword">if</span>(session != <span class="hljs-keyword">null</span>){
                session.close();
            }
        }
        <span class="hljs-keyword">return</span> list;
    }

}
</code></pre>

<ul>
<li>UserDao实现代码</li>
</ul>

<pre class="prettyprint"><code class=" hljs php">package dao;

import model.User;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">UserDao</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">BaseDao</span>&lt;<span class="hljs-title">User</span>&gt;{</span>

}
</code></pre>

<ul>
<li>UserDaoImpl实现代码</li>
</ul>

<pre class="prettyprint"><code class=" hljs php">package dao.impl;

import model.User;
import dao.UserDao;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserDaoImpl</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">BaseDaoImpl</span>&lt;<span class="hljs-title">User</span>&gt; <span class="hljs-keyword">implements</span> <span class="hljs-title">UserDao</span>{</span>
}
</code></pre>



<h2 id="测试">测试：</h2>



<pre class="prettyprint"><code class=" hljs cs">package dao.impl;

import java.util.List;

import org.junit.Test;

import model.User;
import dao.UserDao;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> UserDao_Test {
    <span class="hljs-comment">//@Test</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">saveTest</span>(){
        User user = <span class="hljs-keyword">new</span> User();
        user.setName(<span class="hljs-string">"aaa"</span>);
        user.setPassword(<span class="hljs-string">"123456"</span>);
        UserDao userDao = <span class="hljs-keyword">new</span> UserDaoImpl();
        userDao.save(user);
    }

    <span class="hljs-comment">//@Test</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">deleteTest</span>(){
        UserDao userDao = <span class="hljs-keyword">new</span> UserDaoImpl();
        userDao.delete(<span class="hljs-number">2</span>);
    }

    <span class="hljs-comment">//@Test</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">findByIdTest</span>(){
        UserDao userDao = <span class="hljs-keyword">new</span> UserDaoImpl();
        User user = userDao.findById(<span class="hljs-number">2</span>);
        System.<span class="hljs-keyword">out</span>.println(user.getName());
    }

    <span class="hljs-comment">//@Test</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">updateTest</span>(){
        UserDao userDao = <span class="hljs-keyword">new</span> UserDaoImpl();
        User user = <span class="hljs-keyword">new</span> User();
        user.setId(<span class="hljs-number">1</span>);
        user.setName(<span class="hljs-string">"yyy"</span>);
        userDao.update(user);
    }

    <span class="hljs-comment">//@Test</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">partUpdateTest</span>(){
        <span class="hljs-keyword">int</span> id = <span class="hljs-number">1</span>;
        String[] names = {<span class="hljs-string">"password"</span>};
        Object[] values = <span class="hljs-keyword">new</span> Object[names.length];
        values[<span class="hljs-number">0</span>] = <span class="hljs-string">"4645654"</span>;
        UserDao userDao = <span class="hljs-keyword">new</span> UserDaoImpl();
        userDao.partUpdate(id, names, values);
    }

    <span class="hljs-comment">//@Test</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">findByHQLTest</span>(){
        <span class="hljs-comment">//String hql = "update User t set t.password=? where t.id=1";</span>
        String hql = <span class="hljs-string">"from User u where u.id = ?"</span>;
        Object[] <span class="hljs-keyword">params</span> = {<span class="hljs-number">1</span>};
        UserDao userDao = <span class="hljs-keyword">new</span> UserDaoImpl();
        User user = userDao.findByHQL(hql, <span class="hljs-keyword">params</span>).<span class="hljs-keyword">get</span>(<span class="hljs-number">0</span>);
        System.<span class="hljs-keyword">out</span>.println(user.toString());
    }


    @Test
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">queryPageTest</span>(){
        <span class="hljs-comment">//插入数据</span>
        <span class="hljs-comment">/*for(int i = 1;i &lt;= 40;i ++){
            this.saveTest();
        }*/</span>
        String hql = <span class="hljs-string">"from User u"</span>;
        UserDao userDao = <span class="hljs-keyword">new</span> UserDaoImpl();
        List&lt;User&gt; users = userDao.queryPage(hql, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>);
        <span class="hljs-keyword">for</span>(User user : users){
            System.<span class="hljs-keyword">out</span>.println(user);
        }
    }
}
</code></pre>

<h2 id="重点描述">重点描述</h2>

<ul>
<li>利用反射机制，获取具体实现类</li>
</ul>



<pre class="prettyprint"><code class=" hljs haskell"><span class="hljs-type">ParameterizedType</span> <span class="hljs-typedef"><span class="hljs-keyword">type</span> = <span class="hljs-container">(<span class="hljs-type">ParameterizedType</span>)</span> this.getClass<span class="hljs-container">()</span>.getGenericSuperclass<span class="hljs-container">()</span>;</span>
        clazz = (<span class="hljs-type">Class</span>&lt;<span class="hljs-type">T</span>&gt;) <span class="hljs-typedef"><span class="hljs-keyword">type</span>.getActualTypeArguments<span class="hljs-container">()</span>[0];</span>
        //<span class="hljs-type">System</span>.out.println(<span class="hljs-string">"DAO的真实实现类是："</span>+this.clazz.getName());</code></pre>

<ul>
<li>对应Hibernate中Session提供的update方法，或对实体的所有属性进行更新，可能导致某些值变为null。当我们只想更新对象部分属性时，可以通过执行hql语句解决这个问题。</li>
</ul>                            </div>
                <link rel="stylesheet" href="http://csdnimg.cn/release/phoenix/production/markdown_views-d4dade9c33.css" />
                    </div>
    </article>
      <div class="readall_box csdn-tracking-statistics" data-mod="popu_376">
          <div class="read_more_mask"></div>
          <a class="btn btn-large btn-gray-fred read_more_btn" target="_self">阅读全文</a>
      </div>
      <div class="article_copyright">
              </div>
      <ul class="article_collect clearfix csdn-tracking-statistics"  data-mod="popu_378">
          <li class="tit">本文已收录于以下专栏：</li>
<!--          [startarticlecolumns]-->
                                <!--          [endarticlecolumns]-->
      </ul>
      <div class="comment_box clearfix">
          <div id="comment_form">
              <div id="commentsbmitarear">
                              </div>
          </div>
      </div>
      <div class="comment_li_outbox">
          <div id="comment_list"></div>
      </div>

      <div class="more_comment">
          <div id="comment_bar" class="trackgin-ad" data-mod="popu_385"></div>
      </div>

      <h3 class="recommend_tit" id="related">相关文章推荐</h3>
      <div class="recommend_list clearfix" id="rasss">
                                                                                      <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/kdc18333608478/article/details/52895867"  target="_blank" strategy="BlogCommendFromBaidu_0">万能的BaseDao设计</a></h2>
                          <div class="summary">
                              BaseDao设计的初衷是为了方便我们的使用，不用写很多的重复的代码，今天就说说它的设计思路。我们就是要用反射加泛型加面向接口编程来实现，从网上找了一个UML图，我们就用下图大体简单设计一下。


 ...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/kdc18333608478" target="_blank" strategy="BlogCommendFromBaidu_0"><img src="http://avatar.csdn.net/0/9/3/3_kdc18333608478.jpg" alt="kdc18333608478" title="kdc18333608478"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/kdc18333608478">kdc18333608478</a></li>
                              <li class="time">2016年10月23日 22:08</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>9535</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                                    <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/v123411739/article/details/23969855"  target="_blank" strategy="BlogCommendFromBaidu_1">BaseDao</a></h2>
                          <div class="summary">
                              1.抽取接口的公共方法：
很多Dao都有公共的方法，定义一个BaseDao写公共的方法，其他Dao继承BaseDao
2.抽取实现类的公共方法：
很多DaoImpl里的实现都有共同的方法，定义一...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/v123411739" target="_blank" strategy="BlogCommendFromBaidu_1"><img src="http://avatar.csdn.net/1/4/2/3_v123411739.jpg" alt="v123411739" title="v123411739"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/v123411739">v123411739</a></li>
                              <li class="time">2014年04月17日 23:05</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>2111</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                      <script>
                      (function() {
                          var s = "_" + Math.random().toString(36).slice(2);
                          document.write('<div id="' + s + '"></div>');
                          (window.slotbydup=window.slotbydup || []).push({
                              id: '4765209',
                              container: s,
                              size: '808,120',
                              display: 'inlay-fix'
                          });
                      })();
                  </script>
                                                                <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/kyle0349/article/details/51914504"  target="_blank" strategy="BlogCommendFromBaidu_2">BaseDao --- dao层的抽取</a></h2>
                          <div class="summary">
                              BaseDao的抽取，优化项目代码。                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/kyle0349" target="_blank" strategy="BlogCommendFromBaidu_2"><img src="http://avatar.csdn.net/8/F/C/3_kyle0349.jpg" alt="kyle0349" title="kyle0349"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/kyle0349">kyle0349</a></li>
                              <li class="time">2016年07月15日 08:52</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>1486</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                                    <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/QQ1012421396/article/details/69665854"  target="_blank" strategy="BlogCommendFromBaidu_3">BaseDao工具类</a></h2>
                          <div class="summary">
                              利用元数据对Dao操作进行抽取

Dao操作通用的步骤：




1.写SQL语句



2.获取连接



3.创建stmt



4.执行sql



a)更新executeUpdate



b...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/QQ1012421396" target="_blank" strategy="BlogCommendFromBaidu_3"><img src="http://avatar.csdn.net/4/B/8/3_qq1012421396.jpg" alt="QQ1012421396" title="QQ1012421396"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/QQ1012421396">QQ1012421396</a></li>
                              <li class="time">2017年04月08日 10:56</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>451</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                                    <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/jianmo777/article/details/50341531"  target="_blank" strategy="BlogCommendFromBaidu_4">java web项目DAO层通用接口BaseDao与实现类BaseDaoImpl</a></h2>
                          <div class="summary">
                              在Spring+hibernate的web项目中，处理数据层通常会使用Spring框架提供的HibernateTemplate类提供的方法。通常的用法是每一个实体类对应的去写DAO层的接口和实现类。每...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/jianmo777" target="_blank" strategy="BlogCommendFromBaidu_4"><img src="http://avatar.csdn.net/A/F/3/3_jianmo777.jpg" alt="jianmo777" title="jianmo777"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/jianmo777">jianmo777</a></li>
                              <li class="time">2015年12月17日 14:43</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>5331</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                        <!-- 广告位：PC端-博客详情通栏7（feed流）-808*120 -->
                  <script>
                      (function() {
                          var s = "_" + Math.random().toString(36).slice(2);
                          document.write('<div id="' + s + '"></div>');
                          (window.slotbydup=window.slotbydup || []).push({
                              id: '4983339',
                              container: s,
                              size: '808,120',
                              display: 'inlay-fix'
                          });
                      })();
                  </script>
                                                                              <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/Tomsheng321/article/details/54865135"  target="_blank" strategy="BlogCommendFromBaidu_5">项目中三大框架整合的BaseDao接口及其实现</a></h2>
                          <div class="summary">
                              BaseDao.java
package cn.itcast.core.dao;

import java.io.Serializable;
import java.util.List;

publ...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/Tomsheng321" target="_blank" strategy="BlogCommendFromBaidu_5"><img src="http://avatar.csdn.net/2/3/9/3_tomsheng321.jpg" alt="Tomsheng321" title="Tomsheng321"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/Tomsheng321">Tomsheng321</a></li>
                              <li class="time">2017年02月04日 18:50</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>285</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                                    <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/hjxgood/article/details/45170349"  target="_blank" strategy="BlogCommendFromBaidu_6">基于hibernate的BaseDAO接口</a></h2>
                          <div class="summary">
                              BaseDao.java
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/hjxgood" target="_blank" strategy="BlogCommendFromBaidu_6"><img src="http://avatar.csdn.net/4/5/F/3_hjxgood.jpg" alt="hjxgood" title="hjxgood"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/hjxgood">hjxgood</a></li>
                              <li class="time">2015年04月21日 14:59</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>15135</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                                    <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/a997208868/article/details/48216609"  target="_blank" strategy="BlogCommendFromBaidu_7">万能的BaseDAO和注解的应用</a></h2>
                          <div class="summary">
                              首先科普一下BaseDAO：
BaseDAO一般是提供从数据库 增加、删除、修改记录、查询所有记录、查询符合某个条件记录、取得某条记录等方法的底层数据操作自定义类。
由于我们可能操作多个数据库表，...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/a997208868" target="_blank" strategy="BlogCommendFromBaidu_7"><img src="http://avatar.csdn.net/2/5/B/3_a997208868.jpg" alt="a997208868" title="a997208868"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/a997208868">a997208868</a></li>
                              <li class="time">2015年09月05日 00:38</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>1316</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                                    <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/paul50060049/article/details/51760927"  target="_blank" strategy="BlogCommendFromBaidu_8">java分层开发中的BaseDao</a></h2>
                          <div class="summary">
                              这里介绍的是在不使用持久层框架的情况下，用Java反射写的BaseDao，简化Dao层的操作，让Dao的实现层每个方法体只有一行。所有的Dao的实现类继承BaseDao。 下面具体讲如何使用BaseD...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/paul50060049" target="_blank" strategy="BlogCommendFromBaidu_8"><img src="http://avatar.csdn.net/E/A/7/3_paul50060049.jpg" alt="paul50060049" title="paul50060049"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/paul50060049">paul50060049</a></li>
                              <li class="time">2016年06月26日 01:07</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>999</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                                                                    <dl class="clearfix csdn-tracking-statistics" data-mod="popu_387" data-poputype="feed"  data-feed-show="false"  data-dsm="post">
                      <dd>
                          <h2><a href="http://blog.csdn.net/buliuhu123/article/details/51873717"  target="_blank" strategy="BlogCommendFromBaidu_9">一种BaseDAO的写法</a></h2>
                          <div class="summary">
                              public abstract class BaseDao {

    @Autowired
    private SessionFactory sessionFactory;


    pub...                          </div>
                          <ul>
                              <li class="avatar_img"><a href="http://blog.csdn.net/buliuhu123" target="_blank" strategy="BlogCommendFromBaidu_9"><img src="http://avatar.csdn.net/F/0/C/3_buliuhu123.jpg" alt="buliuhu123" title="buliuhu123"></a></li>
                              <li class="user_name"><a href="http://blog.csdn.net/buliuhu123">buliuhu123</a></li>
                              <li class="time">2016年07月10日 22:07</li>
                              <li class="visited_num"><i class="icon iconfont icon-read"></i><span>978</span></li>
                          </ul>
                      </dd>
                  </dl>
                                                    </div>
  </main>
<aside>
  <div class="right_box user_info">
      <dl class="inf_bar clearfix">
          <dt class="csdn-tracking-statistics" data-mod="popu_381">
              <a href="http://blog.csdn.net/keeping111" target="_blank">
                  <img src="http://avatar.csdn.net/3/A/E/3_keeping111.jpg" class="avatar_pic">
              </a>
              <span class="medals" title="">
                  </span>
          </dt>
          <dd>
              <h3 class="csdn-tracking-statistics"  data-mod="popu_380"><a href="http://blog.csdn.net/keeping111" target="_blank" id="uid">keeping111</a></h3>
              <span  class="csdn-tracking-statistics" data-mod="popu_379"><a class="btn btn-redborder-small "  id="span_add_follow" target="_self">＋关注</a></span>
          </dd>
      </dl>
      <div class="inf_number_box clearfix">
          <dl>
              <dt>原创</dt>
              <dd>92</dd>
          </dl>
          <dl>
              <dt>粉丝</dt>
              <dd id='fan'>1</dd>
          </dl>
          <dl>
              <dt>喜欢</dt>
              <dd>0</dd>
          </dl>
          <dl>
        <dt>码云</dt>
        <dd>&nbsp;</dd>
      </dl>

      </div>
  <div class="writings">
        <div class="public_signal clearfix">
          <h3>他的最新文章</h3>
          <a href="http://blog.csdn.net/keeping111" target="_blank" class="more"><span>更多文章</span></a>
        </div>
          <ul class="inf_list clearfix csdn-tracking-statistics" data-mod="popu_382">
                            <li class="clearfix">
                  <a href="http://blog.csdn.net/Keeping111/article/details/78712543" target="_blank">vi常用键位</a>
              </li>
                            <li class="clearfix">
                  <a href="http://blog.csdn.net/Keeping111/article/details/77986003" target="_blank">Java编码方式</a>
              </li>
                            <li class="clearfix">
                  <a href="http://blog.csdn.net/Keeping111/article/details/77961780" target="_blank">IEEE754标准</a>
              </li>
                        </ul>
      </div>
  </div>
    <div class="user-hotArticle">
        <h3><a href="#related" >相关推荐</a></h3>
        <ul class="hotArticle-list csdn-tracking-statistics" data-mod="popu_563">
<!--           [StartRelatedArticles]-->
                                                <li>
                        <a href="http://blog.csdn.net/kdc18333608478/article/details/52895867" data-mod="popu_559">万能的BaseDao设计</a>
                                            </li>
                                    <li>
                        <a href="http://blog.csdn.net/v123411739/article/details/23969855" data-mod="popu_560">BaseDao</a>
                                            </li>
                                    <li>
                        <a href="http://blog.csdn.net/kyle0349/article/details/51914504" data-mod="popu_561">BaseDao --- dao层的抽取</a>
                                            </li>
                                    <li>
                        <a href="http://blog.csdn.net/QQ1012421396/article/details/69665854" data-mod="popu_562">BaseDao工具类</a>
                                            </li>
                            <!--            [EndRelatedArticles]-->
        </ul>
    </div>
  <div class="extension_other csdn-tracking-statistics" data-mod="popu_389">
     <!--u3032528-->
    <div class="flashrecommend">
        <script type="text/javascript" src="http://mpb1.iteye.com/bwocoltlyzdec.js"></script>
    </div>
  </div>

<!--    [StartShowSelfColumn]-->
    <!--    [EndShowSelfColumn]-->
    <div class="fixRight">
        <div class="right_box padb0 csdn-tracking-statistics" data-mod="popu_391">
            <h3 class="tit"><span><em>在线课程</em></span></h3>
            <ul class="edu_li clearfix">
<!--            [starteducourses]-->
                                                            <li>
                            <div>
                                <a href="http://edu.csdn.net/course/detail/6134?utm_source=blog7" target="_blank">
                                    <img src="http://img.bss.csdn.net/201712051123224037.jpg" alt="JDK9新特性"
                                         title="JDK9新特性">
                                </a>
                            </div>
                            <div>
                                <p><a href="http://edu.csdn.net/course/detail/6134?utm_source=blog7"
                                      target="_blank">JDK9新特性</a></p>
                                <p>讲师：Array</p>
                            </div>
                        </li>
                                            <li>
                            <div>
                                <a href="http://edu.csdn.net/huiyiCourse/series_detail/73?utm_source=blog7" target="_blank">
                                    <img src="http://img.bss.csdn.net/201712051121584041.jpg" alt="Kubernetes容器云平台实践"
                                         title="Kubernetes容器云平台实践">
                                </a>
                            </div>
                            <div>
                                <p><a href="http://edu.csdn.net/huiyiCourse/series_detail/73?utm_source=blog7"
                                      target="_blank">Kubernetes容器云平台实践</a></p>
                                <p>讲师：李志伟</p>
                            </div>
                        </li>
                                    <!--            [endeducourses]-->
            </ul>
            </div>
        <div class="extension_other csdn-tracking-statistics bottomRcom" data-mod="popu_389" style="position:absolute;z-index:-5;opacity:0;pointer-events:none">
            <!--u3032528-->
            <div class="flashrecommend">
                <!-- 请置于所有广告位代码之前 -->
                <script src="http://dup.baidustatic.com/js/dm.js"></script>

                <!-- 广告位：PC端-博客详情页右侧视窗1（feed流）-300*250 -->
                <script>
                    (function() {
                        var s = "_" + Math.random().toString(36).slice(2);
                        document.write('<div id="' + s + '"></div>');
                        (window.slotbydup=window.slotbydup || []).push({
                            id: '4770930',
                            container: s,
                            size: '300,250',
                            display: 'inlay-fix'
                        });
                    })();
                </script>
            </div>
        </div>

    </div>
    <div class="user-hotArticle">
        <h3>他的热门文章</h3>
        <ul class="hotArticle-list csdn-tracking-statistics" data-mod="popu_521">
<!--            [StartHotArticles]-->
                                                <li>
                        <a href="http://blog.csdn.net/keeping111/article/details/51335703">Inversion(HDU_4911) 归并排序+逆序数对</a>
                        <div class="read list-left"><i class="icon iconfont icon-read"></i><span>3111</span></div>
                    </li>
                                    <li>
                        <a href="http://blog.csdn.net/keeping111/article/details/51335900">平行四边形数(fzoj_2231) 几何</a>
                        <div class="read list-left"><i class="icon iconfont icon-read"></i><span>3107</span></div>
                    </li>
                                    <li>
                        <a href="http://blog.csdn.net/keeping111/article/details/53975787">Hibernate实现BaseDao</a>
                        <div class="read list-left"><i class="icon iconfont icon-read"></i><span>1724</span></div>
                    </li>
                                    <li>
                        <a href="http://blog.csdn.net/keeping111/article/details/50754620">Knapsack problem (FZU_2214,福建省第六届ACM-problemC)  01背包+初始化问题+渐缩问题</a>
                        <div class="read list-left"><i class="icon iconfont icon-read"></i><span>991</span></div>
                    </li>
                                    <li>
                        <a href="http://blog.csdn.net/keeping111/article/details/51351571">找单词（HDU_2082) 母函数</a>
                        <div class="read list-left"><i class="icon iconfont icon-read"></i><span>945</span></div>
                    </li>
                            <!--            [EndHotArticles]-->
        </ul>
    </div>
<!--    [startcustom]-->
    <!--    [endcustom]-->
</aside></div>

<div class="left_fixed">
    <div class="left_show_button">
        <span>
          <i class="icon iconfont icon-youjiantou"></i>
        </span>
    </div>
    <ul class="left_menu">
        <li>
            <button class="left-fixed-btn btn-like csdn-tracking-statistics" data-mod="popu_373" target="_self">
                <a href="javascript:void(0);" class="iconbox border_red"><i class="icon iconfont icon-dianzan"></i></a>
                <a class="txt" href="javascript:void(0);">0</a>
            </button>
        </li>
        <li id="blog_artical_directory">
            <button class="left-fixed-btn left_menu_btn csdn-tracking-statistics" data-mod="popu_372" target="_self">
                <a href="javascript:void(0);" class="iconbox border_black"><i class="icon iconfont icon-mulu"></i></a>
            </button>
        </li>
        <li class="menu_con">
            <div class="list_father">
                <div class="arr_box">
                    <button class="btn-noborder arr-btn scroll-down  left_scroll_down"><i class="icon iconfont icon-xiajiantou"></i></button>
                    <button class="btn-noborder arr-btn scroll-up left_scroll_top"><i class="icon iconfont icon-shangjiantou"></i></button>
                </div>
                <div class="arr"></div>
                <div id="csdnBlogDir"></div>
            </div>
        </li>
        <!--        <li>-->
        <!--            <button class="left-fixed-btn btn-like tracking-ad" data-mod="popu_373" target="_self">-->
        <!--                <span class="iconbox border_red"><i class="icon iconfont icon-xihuan-"></i></span>-->
        <!--                <span class="txt">喜欢</span>-->
        <!--                <span class="untxt">取消喜欢</span>-->
        <!--            </button>-->
        <!--        </li>-->
        <li>
            <button class="left-fixed-btn csdn-tracking-statistics" data-mod="popu_374"  id="com-quick-collect" target="_self">
                <a href="javascript:void(0);" class="iconbox border_purple"><i class="icon iconfont icon-shoucang"></i></a>
            </button>
        </li>
        <li>
            <button class="left-fixed-btn btn-pinglun csdn-tracking-statistics" data-mod="popu_544" >
                <a href="javascript:void(0);" class="iconbox border_purple"><i class="icon iconfont icon-pinglun"></i></a>
            </button>
        </li>
        <li id="share_box">
            <button class="left-fixed-btn  csdn-tracking-statistics"  data-mod="popu_375" target="_self">
                <a href="javascript:void(0);" class="iconbox border_orange"><i class="icon iconfont icon-fenxiang"></i></a>
            </button>
            <div class="bdsharebuttonbox csdn-tracking-statistics" data-mod="popu_172">
                <div class="outside">
                    <span class="iconbox border_red2"><i class="icon iconfont icon-xinlang"></i></span>
                    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"> </a>
                </div>
                <div class="outside">
                    <span class="iconbox border_green"><i class="icon iconfont icon-weixin"></i></span>
                    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"> </a>
                </div>
                <div class="outside">
                    <span class="iconbox border_blue"><i class="icon iconfont icon-QQ"></i></span>
                    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"> </a>
                </div>
            </div>
        </li>
    </ul>
</div>
<div class="right_fixed">
    <div class="r_ico">
        <i class="icon iconfont icon-jubao"></i>
        <span class="txt" id="reportBtn">内容举报</span>
    </div>
    <div class="returnTop">
        <i class="icon iconfont icon-fanhuidingbu"></i>
        <span>返回顶部</span>
    </div>
</div>
<div id="pop_win"></div>
<div id="popup_mask"></div>
<div class="pop_CA_cover" ></div>
<div class="pop pop_CA" >
    <div class="CA_header">
        收藏助手
        <span class="cancel_icon"  id="fapancle" ></span>
    </div>
    <iframe src="" id="collectIframe" frameborder="0" width="100%" height="360"  scrolling="no" ></iframe>
</div>
<!--举报-->
<div id="report_dialog" style="top: 250px; left: 343.5px;"><div id="panel_report">
    <div class="panel_head">不良信息举报</div>
    <form method="post" id="frmReport" class="panel_body">
        <table border="0" cellpadding="0" cellspacing="4" class="pop_table">
            <tbody><tr><td colspan="2">您举报文章：<a href="http://blog.csdn.net/Keeping111/article/details/53975787" target="_blank">Hibernate实现BaseDao</a></td></tr>
            <tr>
                <th style="width:60px;">举报原因：</th>
                <td id="panel_reporttype">
                    <label><input type="radio" class="report_type" id="report_sex" name="report_type" value="1">色情</label>
                    <label><input type="radio" class="report_type" id="report_Politics" name="report_type" value="2">政治</label>
                    <label><input type="radio" class="report_type" id="report_copy" name="report_type" value="3">抄袭</label>
                    <label><input type="radio" class="report_type" id="report_ad" name="report_type" value="4">广告</label>
                    <label><input type="radio" class="report_type" id="report_want" name="report_type" value="5">招聘</label>
                    <label><input type="radio" class="report_type" id="report_call" name="report_type" value="6">骂人</label>
                    <br>
                    <label><input type="radio" class="report_type" id="report_other" name="report_type" value="7">其他</label>
                    <input type="text" name="report_other_content" id="report_other_content" maxlength="30" style="display: none;">
                </td>
            </tr>
            <tr id="panel_originalurl" style="display: none;">
                <th>原文地址：</th>
                <td>
                    <input id="originalurl" value="http://" name="originalurl" type="text" style="width: 90%;">
                </td>
            </tr>
            <tr>
                <th id="sp_reason">原因补充：</th>
                <td>
                    <textarea id="report_description" style="width: 300px;" rows="3" name="report_description"></textarea>
                    <p id="sp_n" style="color:#999;margin:0px;padding:0px;">(最多只允许输入30个字)</p>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input id="btnSubmitReport" name="submit" type="image" align="middle" class="btn_1" src="http://csdnimg.cn/release/phoenix/images/btn_submit.jpg">
                    <span style="padding-left:20px;"></span>
                    <img id="btnCloseReportDialog" src="http://csdnimg.cn/release/phoenix/images/btn_cancel.jpg" align="middle">
                    <div id="error" style="color: Red">
                    </div>
                </td>
            </tr>
            </tbody></table>
    </form>
</div>
    <script language="javascript" type="text/javascript">
        var isComment=0;
        //显示隐藏地址
        $(function () {
          console.log("version:phoenix");
            if(isComment){
                $("#report_description").attr("disabled",true);
                $("#sp_n").hide();
                $("#sp_reason").html("评论内容：");
            }
            $(".report_type").click(function () {
                $("#panel_originalurl,#report_other_content").hide();
                switch ($(this).val()) {
                    case '3':
                        $("#panel_originalurl").show();
                        $("#originalurl").focus();
                        break;
                    case '7':
                        if(isComment){
                            $("#report_other_content").show().focus();
                        }
                        break;
                }

            });

            $("#frmReport").submit(function () {
                if (!currentUserName) {

                    if (confirm("您的操作必须登录，是否登录？")) {
                        location.href = "http://passport.csdn.net/account/login?from=" + encodeURIComponent(location.href);
                        return false;
                    }
                    return false;
                }

                var reportType = $("input[name=report_type]:checked").val();
                if(!reportType){
                    alert("请选择举报原因！");
                    return false;
                }
                var otherInfo = "";
                switch (reportType) {
                    case '3':
                        otherInfo = $("#originalurl").val();
                        if (otherInfo == ""||otherInfo=="http://") {
                            alert("举报抄袭必须提供原创文章地址！");
                            $("#originalurl").focus();
                            return false;
                        } else if(!checkeURL(otherInfo)) {
                            alert("请输入正确的原创文章地址！");
                            $("#originalurl").focus();
                            return false;
                        }
                        break;
                    case '7':
                        otherInfo = $("#report_other_content").val();
                        if (isComment && !otherInfo) {
                            alert("请填写举报的具体原因！");
                            $("#report_other_content").focus();
                            return false;
                        }
                        if(!isComment){
                            if(!$("#report_description").val()){
                                alert("请填写举报的具体原因！");
                                $("#report_description").focus();
                                return false;
                            }
                        }
                        break;
                }
                if(!isComment){
                    if($("#report_description").val().length>30){
                        alert("举报原因最多只允许输入30个字！");
                        return false;
                    }
                }
	            nowTime = {
		            year: new Date().getFullYear(),
		            month: parseInt(new Date().getMonth())+1,
		            day: new Date().getDate(),
		            hours: parseInt(new Date().getHours())+1,
		            minutes: parseInt(new Date().getMinutes())+1,
		            seconds: parseInt(new Date().getSeconds())+1
	            };
	            var data = {
		            articleId: fileName,
		            commentId: 0,
		            reportType: reportType,
		            originalurl: $("#originalurl").val(),
		            report_other_content: $("#report_other_content").val(),
		            report_description: $("#report_description").val(),
		            currentUserName: currentUserName,
		            updatetime: nowTime.year+'/'+nowTime.month+'/'+nowTime.day+' '+ nowTime.hours+':'+nowTime.minutes+':'+seconds,
		            blogUser: username
	            };
	            if(!isComment){//如果是举报文章
		            data.report_other_content = data.report_description;
		            // data.report_description = "1. 神经网络这是一个常见的神经网络的图：这是一个常见的三层神经网络的基本构成，Layer L1是输入层，Layer L2是隐含层";
	            }

	            $.post(blog_address + "/common/report?id="+fileName+"&t=2", data, function (data) {
		            if (data.result == 1){
			            SetError("感谢您的举报，我们会尽快审核！");
		            }else{
			            if (data.content) alert(data.content);
		            }

	            });
                return false;
            });

            $("#btnCloseReportDialog").click(function () {
                CloseDiv();
            });

        });

        //提示后关闭方法
        function SetError(error) {
            $("#btnCloseReportDialog").trigger("click");
            alert(error);
            CloseDiv();
        }

        //关闭方法
        function CloseDiv() {

            $.removeMask();
            $("#report_dialog").hide();
            return false;
        }

        //验证url
        function checkeURL(url){
            return /^http(s)?:\/\/([\w-]+\.)+[\w-]+/i.test(url);
        }
    </script>
</div>
<!--  fixme 后期清理掉  -->
<div id="a52b5334d" style="width: 1px; height: 1px; display: none;">
    <script id="adJs52b5334"></script>
    <script>document.getElementById("adJs52b5334").src = "http://ads.csdn.net/js/opt/52b5334.js?t=" + Math.random();</script>
</div>
<script src="http://c.csdnimg.cn/public/common/libs/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://csdnimg.cn/release/phoenix/bower-libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- <script type="text/javascript" src="http://passport.csdn.net/content/loginbox/login.js"></script> -->
<script>window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "1", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];</script>
<script type="text/javascript" >
    if($(".article_collect li").length==1){$(".article_collect").hide();}
    if($(".article_tags li").length==1){$(".article_tags").hide();}
    $(".edit a").attr("href","http://write.blog.csdn.net/postedit/"+fileName);
    $.each($(".edu_li a"),function(){$(this).attr("href",$(this).attr("href").replace("blog7","blog9"))});
    new CNick('#uid').showNickname();

    if($("#fan").html()=="")
    {
	    $("#fan").html(0);
    }
</script>
<script src="http://c.csdnimg.cn/public/common/append_mark/appendMark.min.js?v=5.00.43" type="text/javascript"></script>
<script type="text/javascript">
    appendMark($('.recommend_list').children('a').find('dt'),$('.extension_other'))
</script>
<div class=""id="loginWrap"></div>
<div class="" id="dlMask"></div>
</body>
